package com.hnit.camellia.mapper;


import com.hnit.camellia.entity.Address;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressMapper {
    /**
     * 根据默认地址查询
     * @return
     */
    @Select("select * from camellia.address where is_default= 1")
    Address getAddressByDefault();


    /**
     * 查询所有
     * @return
     */
    @Select("select * from camellia.address")
    List<Address> getAddressList();

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from camellia.address where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据id更新
     * @param address
     */
    void updateById(Address address);

    /**
     * 添加地址
     * @param address
     */
    @Insert("insert into camellia.address(consignee, phone, detail_address, is_default) values (#{consignee},#{phone},#{detailAddress},#{isDefault})")
    void addAddress(Address address);
}
